/*****************************************************************************************************************************************
******Code for Currie, Mueller-Smith, Rossin-Slater "Violence while in Utero: The Impacts of Assaults During Pregnancy on Birth Outcomes**
******July 2020***********************************************************************************************************************/

*****This code cleans the merged NYC crimes/births data and conducts analyses to produce the following output in the manuscript:

*Figure 1
*Tables 1, 2, 3
*Appendix Figure A2
*Appendix Tables A4, A5, A7, A8, A9, A10-Panel A, A11

*Footnote 20 (number of assaults that occur after actual birth but before expected month of birth)
*Text in Empirical Design section (F-stat for predicting assault during pregnancy)
*Footnote 28 (effects of burglary)


set more off
set matsize 10000

clear all

cap log close

***** Paths to data set locations, results graphs *****
global bulk 
global home 
global results 
global graphs

**** First, run clean_birthoutcomes.do file to clean the births data, then the mergebirths_tocrime.do file to merge births data to crime data


**** Small data set to calculate how many assaults occur after the birth but are coded as being during pregnancy based on conception
**** For footnote 20

use ${bulk}direct_crime.dta, clear

gen assault = OffenseCd==3 | OffenseCd==9
*includes felony and non-felony assaults

*assaults only
keep if assault==1

keep if Crime_RMB>=0 & Crime_RMB<.
***means crime occurs in or after the month of birth

sort Study_ID Crime_RMB
by Study_ID: keep if _n==1
***one obs per birth record

keep Study_ID Crime_RMB

count

save ${bulk}assaults_afterbirth.dta, replace

*****************************************
*****************************************
*****************************************


***** Load merged births/crimes data ****

set scheme s1color

use ${bulk}births_crimes.dta, clear

keep if concep_year>=2004 & concep_year<=2012

global crimeclass felony misdemeanor violation

global crimetypes arson assault f_assault burglary drugs kidnap fraud larceny harassment homicide dui weapons other


**** NOTE: we calculate the total number of crimes during pregnancy in the mergebirths_tocrime.do file


*Here, we calculate the total number of crimes in 10 months after pregnancy (post10-post19) and 10 months before pregnancy (pre1-pre10)

egen totcrimes_post = rowtotal(totcrimes_post10 totcrimes_post11 totcrimes_post12 totcrimes_post13 totcrimes_post14 totcrimes_post15 totcrimes_post16 totcrimes_post17 totcrimes_post18 totcrimes_post19)
egen totcrimes_pre = rowtotal(totcrimes_pre10 totcrimes_pre9 totcrimes_pre8 totcrimes_pre7 totcrimes_pre6 totcrimes_pre5 totcrimes_pre4 totcrimes_pre3 totcrimes_pre2 totcrimes_pre1)



foreach class in $crimeclass {
egen tot`class'_post = rowtotal(tot`class'_post10 tot`class'_post11 tot`class'_post12 tot`class'_post13 tot`class'_post14 tot`class'_post15 tot`class'_post16 tot`class'_post17 tot`class'_post18 tot`class'_post19)
egen tot`class'_pre = rowtotal(tot`class'_pre10 tot`class'_pre9 tot`class'_pre8 tot`class'_pre7 tot`class'_pre6 tot`class'_pre5 tot`class'_pre4 tot`class'_pre3 tot`class'_pre2 tot`class'_pre1)
}

foreach type in $crimetypes {
egen tot`type'_post = rowtotal(tot`type'_post10 tot`type'_post11 tot`type'_post12 tot`type'_post13 tot`type'_post14 tot`type'_post15 tot`type'_post16 tot`type'_post17 tot`type'_post18 tot`type'_post19)
egen tot`type'_pre = rowtotal(tot`type'_pre10 tot`type'_pre9 tot`type'_pre8 tot`type'_pre7 tot`type'_pre6 tot`type'_pre5 tot`type'_pre4 tot`type'_pre3 tot`type'_pre2 tot`type'_pre1)
}


gen anycrimes_preg = totcrimes_preg>0 if totcrimes_preg<.
gen anycrimes_post = totcrimes_post>0 if totcrimes_post<.
gen anycrimes_pre = totcrimes_pre>0 if totcrimes_pre<.

foreach class in $crimeclass {
gen any`class'_preg = tot`class'_preg>0 if tot`class'_preg<.
gen any`class'_post = tot`class'_post>0 if tot`class'_post<.
gen any`class'_pre = tot`class'_pre>0 if tot`class'_pre<.
}

foreach type in $crimetypes {
gen any`type'_preg = tot`type'_preg>0 if tot`type'_preg<.
gen any`type'_post = tot`type'_post>0 if tot`type'_post<.
gen any`type'_pre = tot`type'_pre>0 if tot`type'_pre<.
}

sum anyassault_preg
sum anyassault_post
sum anyassault_pre


/**** TO COMPARE TO PRAMS DATA FOR NYC  (Appendix C)****/
*[not limited to single family homes]
sum anyassault_preg anyf_assault_preg anyharassment_preg

*scale by number units in the building
destring unitsres, replace
sum unitsres if house==1, d
foreach var of varlist anyassault_preg anyf_assault_preg anyharassment_preg {
gen wgt_`var' = `var'/unitsres
}

sum wgt_anyassault_preg wgt_anyf_assault_preg wgt_anyharassment_preg


**** crime/assault rates by months relative to conception

forval i=1/12 {
gen anycrimes_pre`i' = totcrimes_pre`i'>0 if totcrimes_pre`i'<.
foreach class in $crimeclass {
gen any`class'_pre`i' =  tot`class'_pre`i'>0 if tot`class'_pre`i'<.
}
foreach type in $crimetypes {
gen any`type'_pre`i' = tot`type'_pre`i'>0 if tot`type'_pre`i'<.
}
}

forval i=0/45 {
gen anycrimes_post`i' = totcrimes_post`i'>0 if totcrimes_post`i'<.
foreach class in $crimeclass {
gen any`class'_post`i' = tot`class'_post`i'>0 if tot`class'_post`i'<.
}
foreach type in $crimetypes {
gen any`type'_post`i' = tot`type'_post`i'>0 if tot`type'_post`i'<.
}
}


sum anyassault_pre10 anyassault_pre9 anyassault_pre8 anyassault_pre7 anyassault_pre6 anyassault_pre5 anyassault_pre4 anyassault_pre3 anyassault_pre2 anyassault_pre1

sum anyassault_post0 anyassault_post1 anyassault_post2 anyassault_post3 anyassault_post4 anyassault_post5 anyassault_post6 anyassault_post7 anyassault_post8 anyassault_post9

sum anyassault_post10 anyassault_post11 anyassault_post12 anyassault_post13 anyassault_post14 anyassault_post15 anyassault_post16 anyassault_post17 anyassault_post18 anyassault_post19




/***** BBQ SAMPLE: Bronx, Brooklyn, and Queens only ****/

destring mom_borough, replace


gen BBQ = (mom_borough==2|mom_borough==3|mom_borough==4)



***** OBSERVATIONS THAT OVERLAP: RECODE USING THE FIRST OBSERVED ASSAULT / CRIME

foreach type in crimes assault f_assault harassment burglary {

gen any`type'_pregpost = (any`type'_preg==1 & any`type'_post==1)
gen any`type'_prepreg = (any`type'_preg==1 & any`type'_pre==1)
gen any`type'_prepregpost = (any`type'_preg==1 & any`type'_pre==1 & any`type'_post==1)


replace any`type'_pre=1 if any`type'_prepreg==1
replace any`type'_preg=0 if any`type'_prepreg==1
forval i=0/9 {
replace any`type'_post`i' = 0 if any`type'_prepreg==1
}


replace any`type'_preg=1 if any`type'_pregpost==1
replace any`type'_post=0 if any`type'_pregpost==1
forval i=10/19 {
replace any`type'_post`i' = 0 if any`type'_pregpost==1
}


replace any`type'_pre=1 if any`type'_prepregpost==1
replace any`type'_preg = 0 if any`type'_prepregpost==1
replace any`type'_post = 0 if any`type'_prepregpost==1
forval i=0/19 {
replace any`type'_post`i'=0 if any`type'_prepregpost==1
}

}

tab anyassault_pregpost if BBQ==1 & house==1
tab anyassault_prepreg if BBQ==1 & house==1
tab anyassault_prepregpost if BBQ==1 & house==1

tab anyassault_preg if [anyassault_preg==1 | anyassault_post==1] & BBQ==1 & house==1




**** crime/assault rates by trimester; and before and after pregnancy

*any assault
gen anyassault_tri1 = (anyassault_post0==1 | anyassault_post1==1 | anyassault_post2==1)
gen anyassault_tri2 = (anyassault_post3==1 | anyassault_post4==1 | anyassault_post5==1)
gen anyassault_tri3 = (anyassault_post6==1 | anyassault_post7==1 | anyassault_post8==1 | anyassault_post9==1)
***note: 3rd trimester includes 4 months

gen anyassault_post3mo = (anyassault_post10==1 | anyassault_post11==1 | anyassault_post12==1)
gen anyassault_post6mo = (anyassault_post13==1 | anyassault_post14==1 | anyassault_post15==1)
gen anyassault_post10mo = (anyassault_post16==1 | anyassault_post17==1 | anyassault_post18==1 |anyassault_post19==1)

gen anyassault_pre4mo = (anyassault_pre1==1 | anyassault_pre2 ==1 | anyassault_pre3==1 | anyassault_pre4==1 )
gen anyassault_pre7mo = (anyassault_pre5==1 | anyassault_pre6 ==1 | anyassault_pre7==1)
gen anyassault_pre10mo = (anyassault_pre8==1 | anyassault_pre9 ==1 | anyassault_pre10==1)

*felony assault

gen anyf_assault_tri1 = (anyf_assault_post0==1 | anyf_assault_post1==1 | anyf_assault_post2==1)
gen anyf_assault_tri2 = (anyf_assault_post3==1 | anyf_assault_post4==1 | anyf_assault_post5==1)
gen anyf_assault_tri3 = (anyf_assault_post6==1 | anyf_assault_post7==1 | anyf_assault_post8==1 | anyf_assault_post9==1)
***note: 3rd trimester includes 4 months

gen anyf_assault_post3mo = (anyf_assault_post10==1 | anyf_assault_post11==1 | anyf_assault_post12==1)
gen anyf_assault_post6mo = (anyf_assault_post13==1 | anyf_assault_post14==1 | anyf_assault_post15==1)
gen anyf_assault_post10mo = (anyf_assault_post16==1 | anyf_assault_post17==1 | anyf_assault_post18==1 |anyf_assault_post19==1)

gen anyf_assault_pre4mo = (anyf_assault_pre1==1 | anyf_assault_pre2 ==1 | anyf_assault_pre3==1 | anyf_assault_pre4==1 )
gen anyf_assault_pre7mo = (anyf_assault_pre5==1 | anyf_assault_pre6 ==1 | anyf_assault_pre7==1)
gen anyf_assault_pre10mo = (anyf_assault_pre8==1 | anyf_assault_pre9 ==1 | anyf_assault_pre10==1)



*** SINGLE FAMILY HOMES ONLY
keep if house==1
count



************************  Additional data cleaning / merging


**** additional outcomes (lbw, preterm, low Apgar.)

gen lbw = birthweight<2500 if birthweight<.
gen vlbw = birthweight<1500 if birthweight<.
gen hbw = birthweight>4000 if birthweight<.
gen pret = gest_weeks<37 if gest_weeks<.
gen vpret = gest_weeks<34 if gest_weeks<.

gen apgar1_low = apgar1<7 if apgar1<.
gen apgar5_low = apgar5<7 if apgar5<.


gen wgtgain_low = wgtgain<15 if wgtgain<.
gen wgtgain_high = wgtgain>40 if wgtgain<.

gen any_breastfeed = (excl_breastfeed==1|some_breastfeed==1) if excl_breastfeed<. & some_breastfeed<.

gen any_abncong = (any_abnormal==1|any_congen==1) if any_abnormal<. & any_congen<.

label var lbw "Low Birth Weight"
label var vlbw "Very Low Birth Weight"
label var hbw "High Birth Weight"
label var pret "Pre-Term Birth"
label var vpret "Very Pre-Term Birth"
label var apgar1_low "1-Min Apgar less than 7"
label var apgar5_low "5-Min Apgar less than 7"
label var wgtgain_low "Wgt Gain less than 15lbs"
label var wgtgain_high "Wgt Gain more than 40lbs"
label var any_breastfeed "Any Breastfeeding"
label var any_abncong "Any Abnormal or Congenital Conditions"

**** parity
gen parity1 = prevlivebirths==0
gen parity2 = prevlivebirths==1
gen parity3plus = prevlivebirths>=2 & prevlivebirths<.
gen paritymiss = prevlivebirths==.

***mom foreign: recode missing as 0
gen mom_foreignmiss = (mom_foreign==.)
replace mom_foreign = 0 if mom_foreign==.

***dad foreign: recode missing as 0
gen dad_foreignmiss = (dad_foreign==.)
replace dad_foreign = 0 if dad_foreign==.

**** father info missing
gen dadmiss = (dadagemiss==1 & dadeducmiss==1 & dadmissingrace==1 & dad_foreignmiss==1)
tab dadmiss

label var dadmiss "Father Info Missing"


**** Mom education (two categories)
gen momedlow = (momeduc1==1|momeduc2==1)
gen momedhigh = (momeduc3==1|momeduc4==1)

*** Dad education (two categories)
gen dadedlow = (dadeduc1==1|dadeduc2==1)
gen dadedhigh = (dadeduc3==1|dadeduc4==1)


replace assesstot = . if assesstot==0
replace year_built = . if year_built==0

global crimetypes arson assault burglary drugs kidnap fraud larceny harassment homicide dui weapons other


local crimevars anycrimes_preg anyassault_preg anyharassment_preg anyburglary_preg anyarson_preg anydrugs_preg anykidnap_preg anyfraud_preg anylarceny_preg anyhomicide_preg anydui_preg anyweapons_preg anyother_preg


/***************************************************
********************BBQ Sample Only ***************
***************************************************/
keep if BBQ==1


/**** Footnote 20: How many assaults occur after actual birth, but before expected month of birth? ***/

merge 1:1 Study_ID using ${bulk}assaults_afterbirth.dta

tab _merge

gen anyassault_postbirth = (_merge==3)
drop _merge

tab anyassault_preg anyassault_postbirth



/************* TABLES 1 & 2 (Columns 2-5)*************/
*Note: Column 1 in these tables if from national vital statistics data
*Note: Row on share felony assaults calculated in code further below

local momchars "momage momage1 momage4 mom_married momnonhispanicwhite momhispanic momnonhispanicblack momasian mom_foreign momeduc1 momeduc2 momeduc3 momeduc4 parity1 singleton"
local dadchars "dadage dadage1 dadage4 dadnonhispanicwhite dadhispanic dadnonhispanicblack dadasian dad_foreign dadeduc1 dadeduc2 dadeduc3 dadeduc4 dadmiss"

*Table 1

eststo clear

eststo: estpost sum `momchars' if anyassault_preg==0 & anyassault_post==0
eststo: estpost sum `momchars' if anyassault_preg==1 & BBQ==1 
eststo: estpost sum `momchars' if anyassault_post==1 & BBQ==1 




#delimit ;
esttab using ${results}momchars_by_PREPOST_BBQ.tex, main(mean)
stats(N, label("Observations") fmt(%12.0fc)) replace
fragment booktabs mtitles("No Assault" "Assault-Preg" "Assault-Post") label wrap ;
#delimit cr


* Make an additional output table with differences and p-values (merged into table manually)
eststo clear
foreach out in `momchars' {
eststo: reg `out' anyassault_preg if anyassault_preg==1 | anyassault_post==1
}

#delimit ;
esttab using "${results}momchars_by_PREPOST_BBQ_Pvalues.tex", replace fragment booktabs p star(* .1 ** .05 *** .01)   
wrap label varwidth(20)   ;
#delimit cr


*Table 2
eststo clear

eststo: estpost sum `dadchars' if anyassault_preg==0 & anyassault_post==0
eststo: estpost sum `dadchars' if anyassault_preg==1 & BBQ==1 
eststo: estpost sum `dadchars' if anyassault_post==1 & BBQ==1 




#delimit ;
esttab using ${results}dadchars_by_PREPOST_BBQ.tex, main(mean)
stats(N, label("Observations") fmt(%12.0fc)) replace
fragment booktabs mtitles("No Assault" "Assault-Preg" "Assault-Post") label wrap ;
#delimit cr


* Make an additional output table with differences and p-values (merged into table manually)
eststo clear
foreach out in `dadchars' {
eststo: reg `out' anyassault_preg if anyassault_preg==1 | anyassault_post==1
}

#delimit ;
esttab using "${results}dadchars_by_PREPOST_BBQ_Pvalues.tex", replace fragment booktabs p star(* .1 ** .05 *** .01)   
wrap label varwidth(20)   ;
#delimit cr



/************* For text in Empirical Design section *************/


*predicting assault during pregnancy with maternal and paternal characteristics

destring mom_borough, replace

global predict momage1 momage2 momage3 momage4 dadage1 dadage2 dadage3 dadage4 mom_married mom_foreign dad_foreign momnonhispanicwhite momhispanic momnonhispanicblack mommissingrace dadnonhispanicwhite dadhispanic dadnonhispanicblack dadmissingrace momeduc1 momeduc2 momeduc3 momeducmiss dadeduc1 dadeduc2 dadeduc3 dadeducmiss singleton parity1 parity2 paritymiss

eststo clear


eststo: reg anyassault_preg $predict if anyassault_preg==1 | anyassault_post==1, r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
testparm $predict 
estadd scalar test=r(p)
estadd scalar test1=r(F)

eststo: reg anyassault_preg $predict i.concep_year i.concep_month if anyassault_preg==1 | anyassault_post==1, r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
testparm $predict i.concep_year i.concep_month
estadd scalar test=r(p)
estadd scalar test1=r(F)


eststo: reg anyassault_preg $predict i.concep_year i.concep_month i.mom_borough if anyassault_preg==1 | anyassault_post==1, r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
testparm $predict i.concep_year i.concep_month i.mom_borough
estadd scalar test=r(p)
estadd scalar test1=r(F)

#delimit ;
esttab using "${results}predicting_assault_pregBBQ.tex", replace fragment booktabs keep($predict) 
se star(* .1 ** .05 *** .01)  stats(dv test1 test N,  label("Dept. var mean" "F-stat" "P-value" "Indiv. obs.")) 
mgroups("Assault During Pregnancy", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
mtitles("Mom Chars" "$+$ Year/Month FE" "$+$ Borough FE") 
wrap label varwidth(20) brackets   ;
#delimit cr
********************************


/******************** DEFINING GLOBALS WITH OUTCOMES AND CALCULATING INDICES ***********************************/



*NOTE: outcomes are oriented such that a higher value means: worse infant health, more medical services, worse behaviors
* ["worse behaviors" includes NOT taking up WIC] 

*need to reorient some outcomes : birth weight, gestation length, cmale

foreach var of varlist birthweight gest_weeks {
egen max_`var' = max(`var') if `var'!=.
gen inv_`var' = max_`var'-`var'
}

gen cfem = 1-cmale
gen nowic = 1-wic


*mean and SD of control group for each variable, then calculate z-score

foreach var of varlist inv_birthweight lbw vlbw hbw inv_gest_weeks pret vpret apgar1_low any_abncong nicu cfem child_death firsttri_pnc numvisits nowic momsmoke momdruguse mom_depressed wgtgain_low wgtgain_high csection induced anycompl {
egen m_`var' = mean(`var') if anyassault_post==1
sum m_`var'
egen CM_`var' = mean(m_`var')
sum CM_`var'
egen sd_`var' = sd(`var') if anyassault_post==1
sum sd_`var'
egen CSD_`var' = mean(sd_`var')
sum CSD_`var'

gen Z_`var' = (`var'-CM_`var')/CSD_`var'
}

sum Z_inv_birthweight
sum Z_vlbw
sum Z_nowic

**create indices
egen birthout_index = rowmean(Z_vlbw Z_vpret Z_apgar1_low Z_nicu Z_any_abncong Z_child_death)
egen medical_index = rowmean(Z_firsttri_pnc Z_numvisits Z_induced Z_csection Z_anycompl)
egen behavioral_index = rowmean(Z_momsmoke Z_momdruguse Z_mom_depressed Z_wgtgain_low Z_wgtgain_high Z_nowic)
egen appendix_index = rowmean(Z_vlbw Z_vpret Z_apgar1_low Z_nicu Z_any_abncong Z_child_death Z_inv_birthweight Z_lbw Z_inv_gest_weeks Z_pret)
*note: appendix_index includes also the components of birthout_index (so, it's including all possible birth outcomes)




/**************** FIGURE 1 ********************/

gen assault_toconcep = -10 if anyassault_pre10==1
forval i=1/9 {
replace assault_toconcep = -`i' if anyassault_pre`i'==1
}


replace assault_toconcep = 0 if anyassault_post0==1

forval i=1/19 {
replace assault_toconcep = `i' if anyassault_post`i'==1
}


tab assault_toconcep

gen crime_toconcep = -10 if anycrimes_pre10==1
forval i=1/9 {
replace crime_toconcep = -`i' if anycrimes_pre`i'==1
}


replace crime_toconcep = 0 if anycrimes_post0==1

forval i=1/19 {
replace crime_toconcep = `i' if anycrimes_post`i'==1
}

*counting assaults
gen assault = 0
forval i=1/10 {
replace assault = 1 if anyassault_pre`i'==1
}

replace assault = 1 if anyassault_post0==1

forval i=1/19 {
replace assault = 1 if anyassault_post`i'==1
}


#delimit ;
global controls momage1 momage2 momage3 momage4 momagemiss dadage1 dadage2 dadage3 dadage4 dadagemiss 
mom_married mom_foreign dad_foreign momnonhispanicwhite momhispanic momnonhispanicblack momotherrace mommissingrace dadnonhispanicwhite dadhispanic dadnonhispanicblack dadotherrace dadmissingrace 
momeduc1 momeduc2 momeduc3 momeduc4 momeducmiss dadeduc1 dadeduc2 dadeduc3 dadeduc4 dadeducmiss singleton parity1 parity2 parity3plus paritymiss ;
#delimit cr


*Predicted Severe Birth Outcomes Index*
reg birthout_index $controls
predict pr_birthout


preserve
keep if BBQ==1
keep if assault_toconcep>=-10 & assault_toconcep<=19
gen N=1
collapse (sum) N (mean) pr_birthout, by(assault_toconcep)

scatter N assault_toconcep, msymbol(oh) msize(large) mcolor(black) xtitle(Month of Assault Relative to Conception) ytitle(Number Births) xline(-0.5 9.5, lcolor(red)) yscale(range(0 158)) ylabel(0(30)160)

graph export "${graphs}numbirths_monthofassault_BBQ.eps", replace
sh rm -f "${graphs}numbirths_monthofassault_BBQ.pdf"
sh epstopdf "${graphs}numbirths_monthofassault_BBQ.eps"


scatter pr_birthout assault_toconcep, msymbol(oh) msize(large) mcolor(black) xtitle(Month of Assault Relative to Conception) ytitle(Predicted Birth Outcome Index) xline(-0.5 9.5, lcolor(red))

graph export "${graphs}predictedBIRTHOUT_monthofassault_BBQ.eps", replace
sh rm -f "${graphs}predictedBIRTHOUT_monthofassault_BBQ.pdf"
sh epstopdf "${graphs}predictedBIRTHOUT_monthofassault_BBQ.eps"


restore
*************


**** Share felony vs. misdemeanor assaults -- bottom row of Table 1 ****

gen fel_assault = anyf_assault_preg==1 | anyf_assault_post==1
gen misd_assault = [anyassault_preg==1 | anyassault_post==1] & fel_assault==0


label var fel_assault "Felony"
label var misd_assault "Misdemeanor"

eststo clear

eststo: estpost sum fel_assault misd_assault if [anyassault_preg==1|anyassault_post==1] & BBQ==1
eststo: estpost sum fel_assault misd_assault if anyassault_preg==1 & BBQ==1
eststo: estpost sum fel_assault misd_assault if anyassault_post==1 & BBQ==1

#delimit ;
esttab using ${results}assault_fel_misd_by_PREPOST_BBQ.tex, main(mean)
stats(N, label("Observations") fmt(%12.0fc)) replace
fragment booktabs mtitles("All" "Assault-Preg" "Assault-Post") label wrap ;
#delimit cr



/**** SET OUTCOME GLOBALS ******/

global birthout vlbw vpret apgar1_low nicu any_abncong child_death birthout_index appendix_index
global medical firsttri_pnc numvisits induced csection anycompl medical_index
global behavioral momsmoke momdruguse mom_depressed wgtgain_low wgtgain_high nowic behavioral_index
global appendix birthweight lbw gest_weeks pret appendix_index

global indices birthout_index appendix_index medical_index behavioral_index 

global momchars momage mom_married mom_foreign momnonhispanicwhite momhispanic momnonhispanicblack momedlow momedhigh anyriskfactors parity1 singleton

global dadchars dadage dad_foreign dadnonhispanicwhite dadhispanic dadnonhispanicblack dadedlow dadedhigh dadmiss


#delimit ;
global controls momage1 momage2 momage3 momage4 momagemiss dadage1 dadage2 dadage3 dadage4 dadagemiss 
mom_married mom_foreign dad_foreign momnonhispanicwhite momhispanic momnonhispanicblack momotherrace mommissingrace dadnonhispanicwhite dadhispanic dadnonhispanicblack dadotherrace dadmissingrace 
momeduc1 momeduc2 momeduc3 momeduc4 momeducmiss dadeduc1 dadeduc2 dadeduc3 dadeduc4 dadeducmiss singleton parity1 parity2 parity3plus paritymiss ;
#delimit cr



label var anyassault_pre "Assault Before Pregnancy"
label var anyassault_preg "Assault During Pregnancy"
label var anyassault_post "Assault Post Pregnancy"



/**************************************************************************************
***********************ASSAULT DURING PREGNANCY VS. 10 MONTHS AFTER********************
***************************************************************************************/

***** APPENDIX TABLE A8 (individual outcomes) ******

**** BY CRIME TYPE:

global crimetypes assault  

*********************
foreach type in $crimetypes {

eststo clear
foreach out in $birthout {
eststo: reg `out' any`type'_preg $controls i.concep_year i.concep_month if any`type'_preg==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}birthout_any`type'_pregBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(dv N,  label("Dept. var mean" "Indiv. obs.")) 
mtitles("VLBW" "V Pret" "Low 1m Apg" "NICU" "Abn/Con" "Death" "Index" "Br. Index") 
wrap label varwidth(20) brackets   ;
#delimit cr
}

foreach type in $crimetypes {

eststo clear
foreach out in $medical {
eststo: reg `out' any`type'_preg $controls i.concep_year i.concep_month if any`type'_preg==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}medical_any`type'_pregBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(dv N,  label("Dept. var mean" "Indiv. obs.")) 
mtitles("PNC 1Tri" "NVis" "Induc" "Csec" "Compl" "Index") 
wrap label varwidth(20) brackets   ;
#delimit cr
}


foreach type in $crimetypes {

eststo clear
foreach out in $behavioral {
eststo: reg `out' any`type'_preg $controls i.concep_year i.concep_month if any`type'_preg==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}behavioral_any`type'_pregBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(dv N,  label("Dept. var mean" "Indiv. obs.")) 
mtitles("Smoke" "Drugs" "Depr" "Low Wgt" "High Wgt" "No WIC" "Index") 
wrap label varwidth(20) brackets   ;
#delimit cr
}


foreach type in $crimetypes {

eststo clear
foreach out in $appendix {
eststo: reg `out' any`type'_preg $controls i.concep_year i.concep_month if any`type'_preg==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}appendix_any`type'_pregBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(dv N,  label("Dept. var mean" "Indiv. obs.")) 
mtitles("Birwt" "LBW" "Gest" "Pret" "Index") 
wrap label varwidth(20) brackets   ;
#delimit cr
}


/******TABLE 3, Row 1 *****/

foreach type in $crimetypes {

eststo clear
foreach out in $indices {
eststo: reg `out' any`type'_preg $controls i.concep_year i.concep_month if any`type'_preg==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}indices_any`type'_pregBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(N,  label("Indiv. obs.")) 
mtitles("Birth Out" "Broad Birth Out" "Med Serv" "Behav/Well") 
wrap label varwidth(20) brackets   ;
#delimit cr
}


/****** APPENDIX TABLE A4 ******/

*PANEL A
foreach type in $crimetypes {

eststo clear
foreach out in $momchars {
eststo: reg `out' any`type'_preg i.concep_year i.concep_month if any`type'_preg==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}momchars_any`type'_pregBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(dv N,  label("Dept. var mean" "Indiv. obs.")) 
mtitles("Age" "Mar" "For" "Wh" "Hsp" "Bl" "LowEd" "HighEd" "Any Risk" "1st Par" "Sngle") 
wrap label varwidth(20) brackets   ;
#delimit cr
}


*PANEL B
foreach type in $crimetypes {

eststo clear
foreach out in $dadchars {
eststo: reg `out' any`type'_preg i.concep_year i.concep_month if any`type'_preg==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}dadchars_any`type'_pregBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(dv N,  label("Dept. var mean" "Indiv. obs.")) 
mtitles("Age" "For" "Wh" "Hsp" "Bl" "LowEd" "HighEd" "Missing") 
wrap label varwidth(20) brackets   ;
#delimit cr
}


***** APPENDIX TABLE A11 *******

** Oster calculation of beta and delta
** Beta = What would beta be if delta = 1 (i.e. selection on unobservables as big as selection on observables?)
** Delta = What would the relative selection on unobservables have to be to get beta = 0?
** Using R-max = 0.18

#delimit ;
global controls1 singleton parity1 parity2 parity3plus paritymiss ;
global controls2 singleton parity1 parity2 parity3plus paritymiss momage1 momage2 momage3 momage4 momagemiss mom_married mom_foreign momnonhispanicwhite momhispanic momnonhispanicblack momotherrace mommissingrace momeduc1 momeduc2 momeduc3 momeduc4 momeducmiss ;
global controls3 singleton parity1 parity2 parity3plus paritymiss momage1 momage2 momage3 momage4 momagemiss mom_married mom_foreign momnonhispanicwhite momhispanic momnonhispanicblack momotherrace mommissingrace momeduc1 momeduc2 momeduc3 momeduc4 momeducmiss
dadage1 dadage2 dadage3 dadage4 dadagemiss dad_foreign dadnonhispanicwhite dadhispanic dadnonhispanicblack dadotherrace dadmissingrace dadeduc1 dadeduc2 dadeduc3 dadeduc4 dadeducmiss ;
#delimit cr


estimates clear 

reg birthout_index anyassault_preg if anyassault_preg==1 | anyassault_post==1, r
estimates store a1
estadd scalar R=e(r2)

reg birthout_index anyassault_preg i.concep_year i.concep_month if anyassault_preg==1 | anyassault_post==1, r
estimates store a2
estadd scalar R=e(r2)
psacalc beta anyassault_preg, rmax(0.18)
 estadd  scalar test1=r(beta) : a2
psacalc delta anyassault_preg, rmax(0.18)
 estadd  scalar test2=r(delta) : a2

reg birthout_index anyassault_preg $controls1 i.concep_year i.concep_month if anyassault_preg==1 | anyassault_post==1, r
estimates store a3
estadd scalar R=e(r2)
psacalc beta anyassault_preg, rmax(0.18)
 estadd  scalar test1=r(beta) : a3 
psacalc delta anyassault_preg, rmax(0.18)
 estadd  scalar test2=r(delta) : a3

reg birthout_index anyassault_preg $controls2 i.concep_year i.concep_month if anyassault_preg==1 | anyassault_post==1, r
estimates store a4
estadd scalar R=e(r2)
psacalc beta anyassault_preg, rmax(0.18)
 estadd  scalar test1=r(beta) : a4 
psacalc delta anyassault_preg, rmax(0.18)
 estadd  scalar test2=r(delta) : a4 

reg birthout_index anyassault_preg $controls3 i.concep_year i.concep_month if anyassault_preg==1 | anyassault_post==1, r
estimates store a5
estadd scalar R=e(r2)
psacalc beta anyassault_preg, rmax(0.18)
 estadd  scalar test1=r(beta) : a5
psacalc delta anyassault_preg, rmax(0.18)
 estadd  scalar test2=r(delta) : a5

reg birthout_index anyassault_preg $controls3 i.concep_year i.concep_month if anyassault_preg==1 | anyassault_post==1, abs(mom_borough) r
estimates store a6
estadd scalar R=e(r2)
psacalc beta anyassault_preg, rmax(0.18)
 estadd  scalar test1=r(beta) : a6
psacalc delta anyassault_preg, rmax(0.18)
 estadd  scalar test2=r(delta) : a6


file open myfile using "${results}birthout_anyassault_Oster_RMax18.tex", write replace
file write myfile "\begin{tabular}{p{2in} cccccc}" _n "\toprule" _n ///
"    &  (1)  & (2) & (3) & (4) & (5) & (6)  		\\" _n 
file close myfile
	estout `vars'* using "${results}birthout_anyassault_Oster_RMax18.tex", type ///
		append  cells(b(star fmt(%9.3f))  se(par([ ]))) starlevels(* 0.10 ** 0.05 *** 0.01)   ///
		stats(R test1 test2  N, fmt(%9.3f %9.3f %9.3f %9.0f) labels("R^2" "Beta" "Delta" "No. of obs.")) style(tex)  ///
		mlabels(,none) collabels(,none) ///
		keep(anyassault_preg) varlabels(anyassault_preg "\multirow{2}{2in}{Adverse Birth Outcome Index}" ) ///
		prefoot("[.5em]") posthead("\midrule")
file open myfile using "${results}birthout_anyassault_Oster_RMax18.tex", write append
 file write myfile "\bottomrule" _n "\end{tabular}"
file close myfile



/********************************************************************************************************
*****************DIFF-in-DIFF: ASSAULT VS. ANY CRIME, DURING VS. AFTER PREGNANCY ************************
*********************************************************************************************************/

gen anyassault_either = anyassault_preg==1 | anyassault_post==1


label var anyassault_either "Assault During or Post Pregnancy"
label var anyassault_preg "Assault During Pregnancy"


*********TABLE 3, row 2 and APPENDIX TABLE A7 ******
eststo clear
foreach out in $indices {
eststo: reg `out' anyassault_preg anyassault_either anycrimes_preg $controls i.concep_year i.concep_month if anycrimes_preg==1 | anycrimes_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
*estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}indices_anyassault_DDanycrimeBBQ.tex", replace fragment booktabs keep(anyassault_preg anyassault_either anycrimes_preg) 
se star(* .1 ** .05 *** .01)  stats(N,  label("Indiv. obs.")) 
mtitles("Birth Out" "Broad Birth Out" "Med Serv" "Behav/Well" ) 
wrap label varwidth(20) brackets   ;
#delimit cr


***** APPENDIX TABLE A5

*Panel A
eststo clear
foreach out in $momchars {
eststo: reg `out' anyassault_preg anyassault_either anycrimes_preg i.concep_year i.concep_month if anycrimes_preg==1 | anycrimes_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}momchars_anyassault_DDanycrimeBBQ.tex", replace fragment booktabs keep(anyassault_preg anyassault_either anycrimes_preg) 
se star(* .1 ** .05 *** .01)  stats(N,  label("Indiv. obs.")) 
mtitles("Age" "Mar" "For" "Wh" "Hsp" "Bl" "LowEd" "HighEd" "Any Risk" "1st Par" "Sngle")  
wrap label varwidth(20) brackets   ;
#delimit cr

*Panel B
eststo clear
foreach out in $dadchars {
eststo: reg `out' anyassault_preg anyassault_either anycrimes_preg i.concep_year i.concep_month if anycrimes_preg==1 | anycrimes_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}dadchars_anyassault_DDanycrimeBBQ.tex", replace fragment booktabs keep(anyassault_preg anyassault_either anycrimes_preg) 
se star(* .1 ** .05 *** .01)  stats(dv N,  label("Dept. var mean" "Indiv. obs.")) 
mtitles("Age" "For" "Wh" "Hsp" "Bl" "LowEd" "HighEd" "Missing") 
wrap label varwidth(20) brackets   ;
#delimit cr
*************************

*****************Footnote 28: Effects of burglary 

label var anyburglary_preg "Burglary During Pregnancy"


**************************
eststo clear
foreach out in $indices {
eststo: reg `out' anyburglary_preg $controls i.concep_year i.concep_month if anyburglary_preg==1 | anyburglary_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
*estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}indices_anyburglaryBBQ.tex", replace fragment booktabs keep(anyburglary_preg) 
se star(* .1 ** .05 *** .01)  stats(N,  label("Indiv. obs.")) 
mtitles("Birth Out" "Broad Birth Out" "Med Serv" "Behav/Well") 
wrap label varwidth(20) brackets   ;
#delimit cr




/***************************************************************************************************************************
***********************REGRESSIONS: ASSAULT DURING PREGNANCY VS. 10 MONTHS BEFORE OR AFTER**********************************
****************************************************************************************************************************/


*******APPENDIX TABLE A10, Panel A
global crimetypes assault

foreach type in $crimetypes {

eststo clear
foreach out in $indices {
eststo: reg `out' any`type'_preg $controls i.concep_year i.concep_month if any`type'_preg==1 | any`type'_pre==1 | any`type'_post==1, abs(mom_borough) r
qui sum `e(depvar)' if e(sample)==1
*estadd scalar dv=`r(mean)'
}

#delimit ;
esttab using "${results}indices_any`type'_pregPREPOSTBBQ.tex", replace fragment booktabs keep(any`type'_preg) 
se star(* .1 ** .05 *** .01)  stats(N,  label("Indiv. obs.")) 
mtitles("Birth Out" "Broad Birth Out" "Med Serv" "Behav/Well") 
wrap label varwidth(20) brackets   ;
#delimit cr
}



/***************** EVENT-STUDY GRAPHS  ***********************/

**** APPENDIX FIGURE A2

label var anyassault_pre10mo "-3 Pre"
label var anyassault_pre7mo "-2 Pre"
label var anyassault_pre4mo "-1 Pre"
label var anyassault_tri1 "1 Tri"
label var anyassault_tri2 "2 Tri"
label var anyassault_tri3 "3 Tri"
label var anyassault_post3mo "1 Post"
label var anyassault_post6mo "2 Post"
label var anyassault_post10mo "3 Post"

foreach var of varlist $birthout {
areg `var' anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo $controls i.concep_year i.concep_month if anyassault_pre==1 | anyassault_preg==1 | anyassault_post==1, abs(mom_borough) r
#delimit ;
coefplot, keep(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo) levels(95 90) legend(order(1 "95% CI" 2 "90% CI")) vertical yline(0, lcolor(black))
mlabel format(%9.3f) order(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 . anyassault_post6mo anyassault_post10mo);
#delimit cr
graph export "${graphs}ES_`var'_assaultBBQ.eps", replace
sh rm -f "${graphs}ES_`var'_assaultBBQ.pdf"
sh epstopdf "${graphs}ES_`var'_assaultBBQ.eps"
}


foreach var of varlist $medical {
areg `var' anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo $controls i.concep_year i.concep_month if anyassault_pre==1 | anyassault_preg==1 | anyassault_post==1, abs(mom_borough) r
#delimit ;
coefplot, keep(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo) levels(95 90) legend(order(1 "95% CI" 2 "90% CI")) vertical yline(0, lcolor(black))
mlabel format(%9.3f) order(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 . anyassault_post6mo anyassault_post10mo);
#delimit cr
graph export "${graphs}ES_`var'_assaultBBQ.eps", replace
sh rm -f "${graphs}ES_`var'_assaultBBQ.pdf"
sh epstopdf "${graphs}ES_`var'_assaultBBQ.eps"
}


foreach var of varlist $behavioral {
areg `var' anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo $controls i.concep_year i.concep_month if anyassault_pre==1 | anyassault_preg==1 | anyassault_post==1, abs(mom_borough) r
#delimit ;
coefplot, keep(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo) levels(95 90) legend(order(1 "95% CI" 2 "90% CI")) vertical yline(0, lcolor(black))
mlabel format(%9.3f) order(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 . anyassault_post6mo anyassault_post10mo);
#delimit cr
graph export "${graphs}ES_`var'_assaultBBQ.eps", replace
sh rm -f "${graphs}ES_`var'_assaultBBQ.pdf"
sh epstopdf "${graphs}ES_`var'_assaultBBQ.eps"
}



foreach var of varlist $appendix {
areg `var' anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo $controls i.concep_year i.concep_month if anyassault_pre==1 | anyassault_preg==1 | anyassault_post==1, abs(mom_borough) r
#delimit ;
coefplot, keep(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 anyassault_post6mo anyassault_post10mo) levels(95 90) legend(order(1 "95% CI" 2 "90% CI")) vertical yline(0, lcolor(black))
mlabel format(%9.3f) order(anyassault_pre10mo anyassault_pre7mo anyassault_pre4mo anyassault_tri1 anyassault_tri2 anyassault_tri3 . anyassault_post6mo anyassault_post10mo);
#delimit cr
graph export "${graphs}ES_`var'_assaultBBQ.eps", replace
sh rm -f "${graphs}ES_`var'_assaultBBQ.pdf"
sh epstopdf "${graphs}ES_`var'_assaultBBQ.eps"
}



